package chpt08;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
public class ReaderWriterTest{
	public static void main(String[] args) throws IOException{
		String str = "你好！Java！";
		String filename = "example.txt";
		try(FileWriter out = new FileWriter(filename,Charset.forName("UTF-8"))){		
			out.write(str);
		}
		try(FileReader in = new FileReader(filename,Charset.forName("UTF-8"))){
			char[] contents = new char[256];
			int len = in.read(contents);
			String msg = new String(contents,0,len);
			System.out.println(msg);
		}		
	}		
}